--CLIENTE
CREATE OR REPLACE FUNCTION sp_update_clientes(cedula character varying, nombre character varying, apellido character varying, direccion character varying, telefono character varying)
  RETURNS void AS
$BODY$
 BEGIN
UPDATE public."Clientes" SET "txtCI"=CEDULA,"txtNombre"=NOMBRE,"txtApellido"=APELLIDO,"txtDireccion"=DIRECCION,"txtNumTlfno"=TELEFONO 
WHERE "txtCI"=CEDULA; 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  
--PROVEEDOR
CREATE OR REPLACE FUNCTION sp_update_proveedor(empresa character varying, contacto character varying, cargo character varying, direccion character varying, ciudad character varying, telefono1 character varying, telefono2 character varying, telefono3 character varying)
  RETURNS void AS
$BODY$
 BEGIN
UPDATE public."Proveedores"  SET "txtNomEmpresa"=EMPRESA,
"txtNomContacto"=CONTACTO,
"txtCargoContacto"=CARGO,
"txtDireccion"=DIRECCION,
"txtCiudad"=CIUDAD,
"txtNumTlfno1"=TELEFONO1,
"txtNumTlfno2"=TELEFONO2,
"txtNumTlfno3"=TELEFONO3 
WHERE "txtNomEmpresa"=EMPRESA;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_update_proveedor(character varying, character varying, character varying, character varying, character varying, character varying, character varying, character varying)
  OWNER TO postgres;
 
 --EMPLEADO
 CREATE OR REPLACE FUNCTION sp_update_empleado(cedula character varying, nombre character varying, apellido character varying, direccion character varying, telefono1 character varying, telefono2 character varying)
  RETURNS void AS
$BODY$
 BEGIN
UPDATE public."Empleados" SET "txtNombre"=NOMBRE,
"txtApellido"=APELLIDO,
"txtDireccion"=DIRECCION,
"txtNumTlfno1"=TELEFONO1,
"txtNumTlfno2"=TELEFONO2 
WHERE "txtCIEmpleado"=CEDULA; 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_update_empleado(character varying, character varying, character varying, character varying, character varying, character varying)
  OWNER TO postgres;
  
--EMPLEADO_USERS
CREATE OR REPLACE FUNCTION sp_update_empleado_users(codigo integer, usuario character varying, passwd character varying, rol character varying)
  RETURNS void AS
$BODY$
 BEGIN
UPDATE public."EMPLEADO_USERS" SET "txtUser"=USUARIO,
"txtPasswd"=PASSWD,
"txtRol"=ROL 
WHERE "numIDEmpleado"=CODIGO; 
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION sp_update_empleado_users(integer, character varying, character varying, character varying)
  OWNER TO postgres;
 
 --CATEGORIAS
CREATE OR REPLACE FUNCTION sp_update_categorias(codigo integer, descripcion character varying, numgd double precision, numgcfinal double precision)
  RETURNS void AS
$BODY$ 
BEGIN
UPDATE public."Categorias" SET "txtNombreCategoria" = $2,
"numGDistribuidor" = $3,
"numGCF" = $4
WHERE "numIDCategoria" = codigo;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

--PRODUCTO_PROVEEDOR
 CREATE OR REPLACE FUNCTION sp_update_PRODUCTO_PROVEEDOR(numIDProd int ,numIDProv int)
  RETURNS void AS
$BODY$ 
BEGIN
UPDATE public."PRODUCTO_PROVEEDOR" 
SET "numIDProveedor" = $2
WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

--PRODUCTO_INVENTARIO
 CREATE OR REPLACE FUNCTION sp_update_PRODUCTO_INVENTARIO(numIDProd int, numCantMin double precision,numCantActual double precision, date character varying)
  RETURNS void AS
$BODY$ 
BEGIN
UPDATE public."PRODUCTO_INVENTARIO" 
SET "numCantMin" = $2,
"numCantActual" = $3,
"dateFechaCompra" = $4
WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

  
  --PRODUCTO
 CREATE OR REPLACE FUNCTION sp_update_producto(numIDProd int, nombre character varying, unid character varying, 
 PC double precision,PF double precision,numProv int, numProd int)
  RETURNS void AS
$BODY$ 
BEGIN
UPDATE public."Productos" 
SET "txtNomProducto" = $2,
"txtDescripUnid" = $3,
"numPrecioCosto" = $4,
"txtPrecioVF" = $5,
"numIDProveedor" = $6,
"numIDCategoria" = $7
WHERE "numIDProducto" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;
 
 --FACTURA
  CREATE OR REPLACE FUNCTION sp_update_factura(numIDFact int, numIDCli int, numIDEmp int,
 txtFP character varying, numST double precision, txtEst character varying, txtFec character varying)
  RETURNS void AS
$BODY$ 
BEGIN
UPDATE public."Facturas" 
SET "numIDCliente" = $2,
"numIDEmpleado" = $3,
"txtFormaPago" = $4,
"numSubTotal" = $5,
"txtEstado" = $6,
"dateFechaFactura" = $7
WHERE "numIDFactura" = $1;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;
  